﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Helper
{
    public class ErrorLogger
    {
        private ErrorLogger()
        { 
        
        }
        /// <summary>
        /// Write the error log of the application
        /// </summary>
        /// <param name="title"></param>
        /// <param name="msg"></param>
        public static void WriteLog(string title, Exception ex)
        {

            try
            {
                //error log to local file
                string AppFolder = "iTracker_Log";
                if (!System.IO.Directory.Exists(@"C:\\" + AppFolder))
                {
                    System.IO.Directory.CreateDirectory(@"C:\\" + AppFolder);
                }

                string activity_fileName = @"C:\\" + AppFolder + "\\error_" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt";
                using (StreamWriter writetext = new StreamWriter(activity_fileName, true))
                {
                    writetext.WriteLine(DateTime.Now.ToShortTimeString());
                    writetext.WriteLine(title);
                    writetext.WriteLine(ex.Message);
                }
            }
            catch (Exception e)
            {

            }
            
        }
    }
}
